﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Web.Http;

namespace Convertor_Utility.Controllers
{
    //to convert image to PDF
    public class ImageToPdfConvertorController : ApiController
    {
        //[HttpPost]
        //public HttpResponseMessage imageToPdf()
        //{

            //var stream = new MemoryStream();
            //// processing the stream.

            //var result = new HttpResponseMessage(HttpStatusCode.OK)
            //{
            //    Content = new ByteArrayContent(stream.GetBuffer())
            //};
            //result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
            //{
            //    FileName = "Hello.pdf"
            //};
            //result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
           
       // }

        [HttpGet]
        public HttpResponseMessage imageToPdf()
        {
            var path = System.Web.HttpContext.Current.Server.MapPath("~/Hello.pdf"); ;
            HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
            var stream = new FileStream(path, FileMode.Open);
            result.Content = new StreamContent(stream);
            result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
            result.Content.Headers.ContentDisposition.FileName = Path.GetFileName(path);
            result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
            result.Content.Headers.ContentLength = stream.Length;
            return result;
        }
    }
}
